<?php
use \yii\helpers\Url;
use \yii\helpers\Html;
use \common\models\Catalog;
use \common\models\Post;
use \common\models\Banner;
use \common\models\Links;
use yii\widgets\ListView;
use yii\bootstrap\BootstrapAsset;
use yii\web\JqueryAsset;
?><!--catalog-->
<!--/* @description 新闻中心 */-->

<?php
$models=$dataProvider->getModels();
$pagination=$dataProvider->getPagination();
$pages=$pagination->getPageCount();
$curr_page=$pagination->getPage()+1;//当前页
$alias=Yii::$app->view->params['alias'];
$navItems = Catalog::getNavItems(3,'news');
if($navItems['childItems']){
    $navItems=$navItems['childItems'];
}
?>
<?php
$photos = Banner::photos('首页');
?>
<script>
    var pages=Number('<?=$pages?>');
    var curr_page=Number('<?=$curr_page?>');
    var c_alias='<?=$alias?>';
    <?php if($alias){?>
    //    list=<?//=$page_size?>//;
    list=20;
    paging=1;
    <?php }?>
</script>
<div  class="banner">
    <div class="hd">
        <ul>
            <?php foreach ($photos as $photo){?>
                <li></li>
            <?php }?>
        </ul>
    </div>
    <div class="bd">
        <ul>
            <?php foreach ($photos as $photo){?>
                <li><a href="<?=$photo['url']?$photo['url']:'#'?>"><img src="<?=$photo['src']?>" /></a></li>
            <?php }?>
        </ul>
    </div>
    <a class="prev" href="javascript:void(0)"></a>
    <a class="next" href="javascript:void(0)"></a>
</div>
<script type="text/javascript">
    jQuery(".banner").slide({mainCell:".bd ul",autoPlay:true,effect:"fold",interTime:"2500"});
</script>
<!--<div class="online_box" style="top:733px;">-->
<!--    <img src="images/online.png">-->
<!--    <div>-->
<!--        <p><img src="images/online_contact.png"><span>科牌-小燕</span></p>-->
<!--        <p><img src="images/online_contact.png"><span>科牌-小燕</span></p>-->
<!--    </div>-->
<!--</div>-->
<div class="content wrapper">

    <div class="content_box">
        <div class="product_display clearfix">
            <div class="pull-left">
                <p>新闻中心<br><span>NEWS</span></p>
                <ul>
                    <?php
                    for($i=0;$i<count($navItems);$i++){
                        $nav=$navItems[$i];
                        ?>
                        <li data-url="<?=Url::to(['/catalog','alias'=>$nav['alias']])?>" data-alias="<?=$nav['alias']?>" class="<?=$alias==$nav['alias']?'on':''?>" onclick="skip(this)"><a href="javascript:;"><?=$nav['name']?><span><img src="images/flag<?=$i+1?>.png"></span></a></li>
                        <?php
                    }
                    ?>
                    <li></li>
                </ul>
            </div>
            <div class="pull-right">
                <div class="pro_detail ">
                    <div class="title clearfix">
                        <p class="pro_tit"><?=$catalog['name']?></p>
                        <p>首 页  >  新闻中心  >  <?=$catalog['name']?></p>
                    </div>
                    <div class="news_list" id="news-list">
                    </div>
                    <?php if($pages){?>
                        <div class="page_box clearfix">
                            <a class="prev" href="javascript:;">上一页</a>
                            <span>
                        <?php $a=0; for($i=1;$i<=$pages;$i++){?>
                            <a class="<?=$i==$curr_page?'on':''?>" href="javascript:;"><?=$i?></a>
                            <?php $a++;if($a==2){
                                break;
                            }}?>
                    </span>
                            <a class="next" href="javascript:;">下一页</a>
                        </div>
                        <script>
                            pageGroup(curr_page,pages);
                            $(document).on('click',".page_box span a",function () {
                                var index=Number($(this).text());
                                pageGroup(index,pages);
                                getNews('<?=Url::toRoute('base/ajax-news')?>','<?=$alias?>',index);
                            });
                            $(document).on('click','.prev',function () {
                                var index=Number($(".page_box span .on").text());
                                pageUp(index,pages);
                                index=Number($(".page_box span .on").text());
                                getNews('<?=Url::toRoute('base/ajax-news')?>','<?=$alias?>',index);
                            });
                            $(document).on('click','.next',function () {
                                var index=Number($(".page_box span .on").text());
                                pageDown(index,pages);
                                index=Number($(".page_box span .on").text());
                                getNews('<?=Url::toRoute('base/ajax-news')?>','<?=$alias?>',index);
                            });
                        </script>
                    <?php }?>
                </div>

            </div>

        </div>
    </div>
</div>
<script>
    $(function () {
        $(".pull-left ul li").each(function () {
            if ($(this).attr("data-alias") == c_alias) {
                var a = $(this).attr("data-alias");
                $(this).addClass("on");
                $.get("<?=Url::toRoute('base/ajax-news')?>",
                    {
                        alias: a,
                        list: list,
                        paging: paging
                    },
                    function (data, status) {
                        $("#news-list").empty();
                        $("#news-list").append(data);
                    });
            }
        });
    })
</script>